package com.dailyblue.project.estate.commons.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.dailyblue.project.estate.commons.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
public class TimeHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject meta) {
        log.info("开始自动填充时间");
        this.strictInsertFill(meta, "createTime", DateUtil::getNowDateTime, String.class);
        //this.strictInsertFill(meta, "create_time", LocalDateTime.class, LocalDateTime.now());
        //this.strictInsertFill(meta, "createTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject meta) {
        this.strictInsertFill(meta, "update_time", DateUtil::getNowDateTime, String.class);
    }
}
